package com.bj.jiufu.util.redis;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisStringUtil {
	/** 日志实例 */
	private static final Logger logger = Logger
			.getLogger(RedisStringUtil.class);

	private static JedisPool jedisPool = RedisPoll.getInstance();

	public static String get(String key) {
		Jedis jedis = null;
		String result = null;
		try {
			if (jedisPool == null)
				jedisPool = RedisPoll.getInstance();
			jedis = jedisPool.getResource();
			result = jedis.get(key);
		} catch (Exception e) {
			logger.error(e);
			return null;
		} finally {
			if (null != jedis) {
				jedis.close();
			}
		}
		return result;

	}

	public static String set(String key, String value) {
		Jedis jedis = null;
		String result = null;
		try {
			if (jedisPool == null)
				jedisPool = RedisPoll.getInstance();
			jedis = jedisPool.getResource();
			result = jedis.set(key, value);

		} catch (Exception e) {
			logger.error(e);
		} finally {
			if (null != jedis) {
				jedis.close();
			}
		}
		return result;
	}

	public static Long delete(String key) {
		Jedis jedis = null;
		Long result = null;
		try {
			if (jedisPool == null)
				jedisPool = RedisPoll.getInstance();
			jedis = jedisPool.getResource();
			result = jedis.del(key);

		} catch (Exception e) {
			logger.error(e);
		} finally {
			if (null != jedis) {
				jedis.close();
			}
		}
		return result;
	}

}
